
function outputThreadINfo(){
        echo "restart ..."
        #$1 输出线程的关键字，如果时多个用 , 分割
        #$2 输出线程执行情况次数
        #$3 当多次输出线程执行情况时,多次之间的间隔

	if [ -z $1 ]
	then
	   echo "$1 : 进程的名称必须参数"
	   return 1
	fi
	
	cycles=1;
	if [ "$2" ]
	then
		cycles=$2
	fi

	waitingTime=3;
	if [ "$3" ]
	then
		waitingTime=$3
	fi

	OLD_IFS="$IFS"
	IFS=","
	processNames=($1)
	IFS="$OLD_IFS"
	
	saveDir=jvmThread
	if [ ! -d $saveDir ]; then
		mkdir $saveDir	
	fi

	curCycle=1
	while [ "$curCycle" -le "$cycles" ] ; do
	#while [ "$curCycle" -le 1 ] ; do
		for processName in ${processNames[@]}
		do
			PID=$(ps -ef|grep ${processName}|grep -v grep|awk '{print $2}');
			jstack -l ${PID} > ${saveDir}/thread.${processName}.$(date +%Y%m%d_%H%M%S).${curCycle}.log;
			#echo "jstack -l ${PID} >  thread.${processName}.${curCycle}.log";
			echo "Output thread information of the [${processName}] process.";
		done
		curCycle=`expr $curCycle + 1 `
		if [ "$curCycle" -le "$cycles" ]
		then
			echo "Please wait for output thread iNfo."
			sleep $waitingTime
		fi
	done
	return 0;
}

cycles=1
waitingTime=2
processNames="koauth,ktrade,kfat"

if [ "$1" ]
then
	cycles=$1
fi

if [ "$2" ]
then
	waitingTime=$2
fi

if [ "$3"]
then
	processNames=$3
fi



outputThreadINfo  ${processNames} ${cycles} ${waitingTime}
#outputThreadINfo
